package com.jcoinexchange.web.exception;

import com.jcoinexchange.web.entity.ResponseCode;
import com.jcoinexchange.web.util.StringFormatUtil;


/**
 * @desc 外部服务调用异常
 *
 * @author tony
 * @createDate 2024/4/8 10:51 上午
 */
public class ExternalException extends RuntimeException{

    private int code;
    private String errorMsg;

    private ExternalException(){}

    public ExternalException(ResponseCode errorCode) {
        super(errorCode.getMsg());
        this.code = errorCode.getCode();
        this.errorMsg = errorCode.getMsg();
    }

    public ExternalException(ResponseCode errorCode, String format, Object... args) {
        super(StringFormatUtil.format(format, args));
        this.code = errorCode.getCode();
        this.errorMsg = StringFormatUtil.format(format, args);
    }

    public int getCode() {
        return code;
    }

    public String getErrorMsg() {
        return errorMsg;
    }
}
